<?php

namespace Database\Seeders;

use App\Models\Permission;
use Illuminate\Database\Seeder;

class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $permissions = [
            // 用户管理权限
            ['name' => '用户查看', 'code' => 'users.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'users', 'action' => Permission::ACTION_VIEW],
            ['name' => '用户新增', 'code' => 'users.create', 'type' => Permission::TYPE_BUTTON, 'resource' => 'users', 'action' => Permission::ACTION_CREATE],
            ['name' => '用户编辑', 'code' => 'users.update', 'type' => Permission::TYPE_BUTTON, 'resource' => 'users', 'action' => Permission::ACTION_UPDATE],
            ['name' => '用户删除', 'code' => 'users.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'users', 'action' => Permission::ACTION_DELETE],
            ['name' => '用户导出', 'code' => 'users.export', 'type' => Permission::TYPE_BUTTON, 'resource' => 'users', 'action' => Permission::ACTION_EXPORT],
            ['name' => '用户分配', 'code' => 'users.assign', 'type' => Permission::TYPE_BUTTON, 'resource' => 'users', 'action' => Permission::ACTION_ASSIGN],

            // 角色管理权限
            ['name' => '角色查看', 'code' => 'roles.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'roles', 'action' => Permission::ACTION_VIEW],
            ['name' => '角色新增', 'code' => 'roles.create', 'type' => Permission::TYPE_BUTTON, 'resource' => 'roles', 'action' => Permission::ACTION_CREATE],
            ['name' => '角色编辑', 'code' => 'roles.update', 'type' => Permission::TYPE_BUTTON, 'resource' => 'roles', 'action' => Permission::ACTION_UPDATE],
            ['name' => '角色删除', 'code' => 'roles.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'roles', 'action' => Permission::ACTION_DELETE],

            // 菜单管理权限
            ['name' => '菜单查看', 'code' => 'menus.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'menus', 'action' => Permission::ACTION_VIEW],
            ['name' => '菜单新增', 'code' => 'menus.create', 'type' => Permission::TYPE_BUTTON, 'resource' => 'menus', 'action' => Permission::ACTION_CREATE],
            ['name' => '菜单编辑', 'code' => 'menus.update', 'type' => Permission::TYPE_BUTTON, 'resource' => 'menus', 'action' => Permission::ACTION_UPDATE],
            ['name' => '菜单删除', 'code' => 'menus.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'menus', 'action' => Permission::ACTION_DELETE],

            // 权限管理权限
            ['name' => '权限查看', 'code' => 'permissions.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'permissions', 'action' => Permission::ACTION_VIEW],
            ['name' => '权限新增', 'code' => 'permissions.create', 'type' => Permission::TYPE_BUTTON, 'resource' => 'permissions', 'action' => Permission::ACTION_CREATE],
            ['name' => '权限编辑', 'code' => 'permissions.update', 'type' => Permission::TYPE_BUTTON, 'resource' => 'permissions', 'action' => Permission::ACTION_UPDATE],
            ['name' => '权限删除', 'code' => 'permissions.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'permissions', 'action' => Permission::ACTION_DELETE],

            // 部门管理权限
            ['name' => '部门查看', 'code' => 'departments.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'departments', 'action' => Permission::ACTION_VIEW],
            ['name' => '部门新增', 'code' => 'departments.create', 'type' => Permission::TYPE_BUTTON, 'resource' => 'departments', 'action' => Permission::ACTION_CREATE],
            ['name' => '部门编辑', 'code' => 'departments.update', 'type' => Permission::TYPE_BUTTON, 'resource' => 'departments', 'action' => Permission::ACTION_UPDATE],
            ['name' => '部门删除', 'code' => 'departments.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'departments', 'action' => Permission::ACTION_DELETE],

            // 操作日志权限
            ['name' => '操作日志查看', 'code' => 'operation_logs.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'operation_logs', 'action' => Permission::ACTION_VIEW],
            ['name' => '操作日志删除', 'code' => 'operation_logs.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'operation_logs', 'action' => Permission::ACTION_DELETE],

            // 登录日志权限
            ['name' => '登录日志查看', 'code' => 'login_logs.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'login_logs', 'action' => Permission::ACTION_VIEW],
            ['name' => '登录日志删除', 'code' => 'login_logs.delete', 'type' => Permission::TYPE_BUTTON, 'resource' => 'login_logs', 'action' => Permission::ACTION_DELETE],

            // 在线用户权限
            ['name' => '在线用户查看', 'code' => 'online_users.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'online_users', 'action' => Permission::ACTION_VIEW],
            ['name' => '在线用户强制登出', 'code' => 'online_users.assign', 'type' => Permission::TYPE_BUTTON, 'resource' => 'online_users', 'action' => Permission::ACTION_ASSIGN],

            // 环境变量配置权限
            ['name' => '环境变量配置查看', 'code' => 'env_config.view', 'type' => Permission::TYPE_BUTTON, 'resource' => 'env_config', 'action' => Permission::ACTION_VIEW],
            ['name' => '环境变量配置编辑', 'code' => 'env_config.update', 'type' => Permission::TYPE_BUTTON, 'resource' => 'env_config', 'action' => Permission::ACTION_UPDATE],
        ];

        foreach ($permissions as $permission) {
            Permission::firstOrCreate(
                ['code' => $permission['code']],
                $permission
            );
        }
    }
}

